package com.ikun.hospayservice.controller;

import com.ikun.common.entity.Convention;
import com.ikun.hospayservice.pojo.AliPay;
import com.ikun.hospayservice.service.AliPayService;
import com.ikun.hospayservice.utils.ProcessOrdersUtil;
import lombok.extern.slf4j.Slf4j;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author sun12
 */
@Slf4j
@RestController
@RequestMapping("alipay")
public class AliPayController {

    @Resource
    private AliPayService aliPayService;



    /**
     * 支付宝支付
     */
    @PostMapping("pay")
    public ResponseEntity<String> pay(@RequestBody Convention convention) {
        String payment = aliPayService.payment(convention);
        return ResponseEntity.ok(payment);
    }


    /**
     * 支付宝退款
     */
    @PostMapping("refund")
    public ResponseEntity<Integer> payNotify(@RequestBody Convention convention) {
        int refund = aliPayService.refund(convention);
        return ResponseEntity.ok(refund);
    }

    /**
     * 支付宝订单查询
     */
    @GetMapping("queryPay")
    public ResponseEntity<String> queryPay(@RequestParam String alipayTraceNo) {
        String state = aliPayService.queryState(alipayTraceNo);
        return ResponseEntity.ok(state);
    }

    /**
     * 支付宝订单取消
     */
    @PostMapping("cancelPay")
    public ResponseEntity<Integer> cancelPay(@RequestBody Convention convention) {
        aliPayService.cancelPay(convention);
        return ResponseEntity.ok(200);
    }


}
